<!-- Main content -->
    <section class="content">

	  <div class="row">
        <div class="col-xs-12">
          <div class="box box-info">
            <div class="box-header">
              <h3 class="box-title">系统用户列表</h3> &emsp;<button type="button" data-toggle="modal" data-target="#exampleModal" class="btn btn-sm btn-success">新建系统用户</button>

              <div class="box-tools">
                <button type="button" id="refresh" class="btn btn-default btn-sm" title="刷新当前页"><i class="fa fa-refresh"></i></button>
              </div>
            </div>
            <!-- /.box-header -->
            <div class="box-body table-responsive no-padding">
              <table class="table table-hover">
               <tbody><tr>
					<th>ID</th>
                  <th>管理员账号</th>
                  <th>用户组</th>
                  <th>账户状态</th>
                  <th>登录次数</th>
                  <th>最后登录时间</th>
                  <th>最后登录IP</th>
				  <th>创建时间</th>
				  <th>操作</th>
                </tr>

        <volist name="admin" id="vo">
        <tr>
		<td>{$i}</td>
		<td>{$vo.username}</td>
		<td>{$vo.groupname}</td>
		<td><switch name="vo['status']">
        <case value="1"><span class="btn btn-success btn-xs">正常</span></case>
        <case value="0"><span class="btn btn-danger btn-xs">禁用</span></case>
        <default />未知
        </switch></td>
		<td>{$vo.login_count}</td>
		<td>{$vo.login_time|date="Y-m-d H:i:s",###}</td>
		<td>{$vo.ip}</td>
		<td>{$vo.create_time|date="Y-m-d H:i:s",###}</td>
		<td>
			<a href="__APP__/admin/admin/admingroupidajax/{$vo.id}" class="btn btn-success btn-xs ajax_return">修改</a>
			<a href="__APP__/admin/admin/state/{$vo.id}" class="btn btn-warning btn-xs ajax_return">开启/禁用</a>
			<a href="__APP__/admin/admin/deladmin/{$vo.id}" class="btn btn-danger btn-xs ajax_return">删除</a>
		</td>
		</tr>
		</volist>

	     
              </tbody></table>
            </div>
            <!-- /.box-body -->

			<div class="box-footer clearfix">
				<ul class="pagination pagination-sm no-margin pull-left">
					共有  {$page.count} 条记录
				</ul>
              <ul class="pagination pagination-sm no-margin pull-right pagelist">
              <for start="0" end="$page.pages" >
                <if condition="$page.page == $i+1"><li class="active"><a href="__APP__/admin/admin/adminlist/{$i+1}">{$i+1}</a></li>
                <else/><li><a href="__APP__/admin/admin/adminlist/{$i+1}">{$i+1}</a></li>
                </if>
              </for>
              </ul>
            </div>

          </div>
          <!-- /.box -->
        </div>
      </div>

    </section>
    <!-- /.content -->
<div class="modal modal-success fade" id="exampleModal" role="dialog" aria-labelledby="exampleModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <form class="form-horizontal" id="addmins" method="post" action="__MODULE__/admin/addadmin">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="exampleModalLabel">新建系统用户</h4>
      </div>
              <div class="modal-body">
                <div class="form-group">
                  <label for="inputname" class="col-sm-2 control-label">账号</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" name="username" id="inputname" placeholder="账号">
                  </div>
                </div>

                <div class="form-group">
                  <label for="inputpw" class="col-sm-2 control-label">密码</label>
                  <div class="col-sm-10">
                    <input type="password" class="form-control" name="password" id="inputpw">
                  </div>
                </div>

                <div class="form-group">
                  <label for="inputckpw" class="col-sm-2 control-label">确认密码</label>
                  <div class="col-sm-10">
                    <input type="password" class="form-control" name="checkpw" id="inputckpw">
                  </div>
                </div>

                <div class="form-group">
                  <label class="col-sm-2 control-label">用户组</label>
                  <div class="col-sm-10">
                  <select class="form-control" name="group_id">
                  <volist name="group" id="vo">
                  <option value="{$vo.id}">{$vo.title}</option>
                  </volist>
                </select>
                  </div>
                </div>
                </div>
              
              <!-- /.modal-body -->
              <div class="modal-footer">
                <p class="pull-left ajaxreturnp"></p>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-info pull-right subtn">确定</button>
              </div>
              <!-- /.box-footer -->
            </form>
      </div>
    </div>
  </div>
</div>
<!--新建用户-->
<div class="modal modal-success fade" id="editadminModal" role="dialog" aria-labelledby="exampleModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <form class="form-horizontal" id="editadminform" method="post" action="__MODULE__/admin/editadmin">
        <input type="hidden" name="userid" id="adminid">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="exampleModalLabel">修改系统用户</h4>
      </div>
              <div class="modal-body">
                <div class="form-group">
                  <label for="inputname" class="col-sm-2 control-label">账号</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" name="username" id="inputname2" >
                  </div>
                </div>

                <div class="form-group">
                  <label for="inputpw" class="col-sm-2 control-label">新密码</label>
                  <div class="col-sm-10">
                    <input type="password" class="form-control" name="password" id="inputpw2">
                  </div>
                </div>

                <div class="form-group">
                  <label for="inputckpw" class="col-sm-2 control-label">确认新密码</label>
                  <div class="col-sm-10">
                    <input type="password" class="form-control" name="checkpw" id="inputckpw2">
                  </div>
                </div>

                <div class="form-group">
                  <label class="col-sm-2 control-label">用户组</label>
                  <div class="col-sm-10">
                  <select class="form-control" name="group_id" id="admingroupid">
                  <volist name="group" id="vo">
                  <option value="{$vo.id}">{$vo.title}</option>
                  </volist>
                </select>
                  </div>
                </div>
                </div>
              
              <!-- /.modal-body -->
              <div class="modal-footer">
                <p class="pull-left ajaxreturnp"></p>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-info pull-right subtn">确定</button>
              </div>
              <!-- /.box-footer -->
            </form>
      </div>
    </div>
  </div>
</div>
<!--修改系统用户-->
<div class="modal modal-danger fade" id="deleteModal" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <form class="form-horizontal" id="deladmin" method="post" action="__MODULE__/admin/deladmin">
      <input type="hidden" name="id" id="inputhidden3">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">删除用户</h4>
      </div>
      <div class="modal-body">
        <p>确定要删除 [<span id="delruletitle3"></span>] 用户吗？删除后不可恢复!</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
        <button type="button" class="btn btn-danger subtn">确定删除</button>
      </div>
      </form>
    </div>
  </div>
</div>
<!--删除系统用户-->

<script type="text/javascript">
  $(".subtn").on("click",function(){
      var formdata = $(this).parent().parent().serialize();
      var url = $(this).parent().parent().attr("action");
      var method = $(this).parent().parent().attr("method");
      if (method == "post") {
        $.post(url,formdata,function(data){
          if (data == '1') {
            $(".modal").modal('hide');
          }else{
            $(".ajaxreturnp").text("操作失败");
          }
        });
      }else if(method == "get"){
          $.get(url,function(data){
              if (data=='1') {
                $(".modal").modal('hide');
              }else{
                $(".ajaxreturnp").text("操作失败");
              }
          });
      } 
  });

  $(".ajax_return").on("click",function(){
      var url = $(this).attr("href");
      var pathurl = url.split("/");
      /**修改用户**/
      if (pathurl[pathurl.length-2] == "admingroupidajax") {
          var username = $(this).parent().siblings().eq(1).text();
          $.get(url,function(data){
            $("#adminid").val(pathurl[pathurl.length-1]);
            $("#inputname2").val(username);
            $("#admingroupid").val(data);
            $("#editadminModal").modal('show');
          });
      /**删除用户**/ 
      }else if(pathurl[pathurl.length-2] == "deladmin"){
          var username = $(this).parent().siblings().eq(1).text();
          $("#inputhidden3").val(pathurl[pathurl.length-1]);
          $("#delruletitle3").text(username);
          $("#deleteModal").modal('show');
      }else{
        if(url&&url!='/'&&url!="#"){
          $.get(url,function(data){
              if (data=='1') {
                refresh();
              }else{
                alert("修改失败");
              }
          });
        }
      } 
  });

  $('.modal').on('hidden.bs.modal', function (){
      refresh();
  })

  $("#refresh").on("click",function(){
      refresh();
  });

  function refresh(){
      var pagei = $(".pagelist li.active").text();
      $("#mcont").load("__MODULE__/admin/adminlist/"+pagei);
  }
</script>